home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / U-Z / VideoToolBox Folder / Utilities / TestAttenuator.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-04  |  4.7 KB  |  195 lines  |  [TEXT/KAHL]

  1. /*
  2. TestAttenuator.c
  3. This produced a simple test pattern that allows a quick yes/no evaluation of the
  4. attenuator before shipping. Mainly this is a check to make sure that all the
  5. resistors were soldered correctly.
  6. HISTORY:
  7. 11/89     dgp wrote it
  8. 9/9/90    dgp    make the arrays static.
  9. 10/17/90    dgp    remove unused variable
  10. 2/16/91        dgp    added check for fpu and color quickdraw
  11. 8/24/91    dgp    Made compatible with THINK C 5.0.
  12. 3/10/92    dgp    include mc68881.h
  13. 4/27/92    dgp    call SetDepth to set screen to 8 bits.
  14. 8/27/92    dgp    replace SysEnvirons() by Gestalt()
  15. 2/7/93    dgp    updated to use SetPixelsQuickly.
  16. */
  17. #include "VideoToolbox.h"
  18. #include <math.h>
  19. #include "Luminance.h"
  20. #if THINK_C
  21.     #include <console.h>
  22. #endif
  23.  
  24. #define XMAX         640        /* Maximum horizontal coordinate */ 
  25. #define YMAX         480        /* Maxumum vertical coordinate */
  26.  
  27. void TestAttenuator(void);
  28.  
  29. void main(void)
  30. {
  31.     Require(gestalt8BitQD);
  32.     TestAttenuator();
  33. }
  34.  
  35. void TestAttenuator(void)
  36. {
  37.     register short i,j,k;
  38.     double a,A,AA;
  39.     CWindowPtr window=NULL;
  40.     WindowPtr oldWindow=NULL;
  41.     GDHandle device=NULL,oldGDHandle=NULL;
  42.     static luminanceRecord LR;
  43.     short n;
  44.     static double fy[YMAX];
  45.     double c;
  46.     static unsigned long row[XMAX];
  47.     short oldScreen;
  48.     char string[100];
  49.     
  50.     /* parameters of the screen calibration */
  51.     
  52.     console_options.top=YMAX/2-40;
  53.     console_options.nrows=7;
  54.     console_options.txSize=9;
  55.     printf("Welcome to TestAttenuator.\n");
  56.     #include "LuminanceRecord1.h"                    // read at compile time
  57.     printf("%s\n",LR.notes);
  58.     oldScreen=LR.screen;
  59.     if(GetScreenDevice(1)!=NULL){
  60.         for(; ;){
  61.             printf("Which screen would you like to calibrate (%d):",LR.screen);
  62.             gets(string);
  63.             sscanf(string,"%d",&LR.screen);
  64.             device=GetScreenDevice(LR.screen);
  65.             if(device!=NULL)break;
  66.             else printf("Sorry, there is no device %d\n",LR.screen);
  67.         }
  68.     }else LR.screen=0;
  69.     sprintf(string,"LuminanceRecord%d.h",LR.screen);
  70.     i=ReadLuminanceRecord(string,&LR,0);        // try to read latest luminanceRecord
  71.     if(i<1)printf("Warning: couldn't find ā€œ%sā€. Calibrating screen %d.\n"
  72.         ,string,LR.screen);
  73.     else oldScreen=LR.screen;
  74.  
  75.     /* Find device corresponding to the experimental screen. */
  76.     oldGDHandle = GetGDevice();
  77.     device = GetScreenDevice(LR.screen);
  78.     if(GDCOLORS(device)!=256 && NewPaletteManager())
  79.         SetDepth(device,8,1,1);            /* 8-bit pixelSize & color mode */
  80.     if(GDCOLORS(device)!=256){
  81.         PrintfExit("Sorry, I require a screen with 256 colors.\n");
  82.     }
  83.     
  84.     GetPort(&oldWindow);
  85.     window = GDOpenWindow(device);
  86.     SetPort((WindowPtr)window);
  87.     
  88.     for(j=0;j<YMAX/2;j++){
  89.         fy[j]=cos(j*2.0*PI/80.0);
  90.     }
  91.     c=1.0;
  92.     SetLuminances(device,&LR,11,90,LR.LMin,LR.LMin+(LR.LMax-LR.LMin)*c);
  93.     c/=6.0;
  94.     SetLuminances(device,&LR,91,170,LR.LMin,LR.LMin+(LR.LMax-LR.LMin)*c);
  95.     c/=6.0;
  96.     SetLuminances(device,&LR,171,250,LR.LMin,LR.LMin+(LR.LMax-LR.LMin)*c);
  97.     /* Display a swept-contrast sinusoid */
  98.     for(j=0;j<YMAX/2;j++){
  99.         k=floor(0.5+79.0*0.5*c*(1.0 + fy[j]));
  100.         k+=11;
  101.         for(i=0;i<1+XMAX/3;i++)row[i]=k;
  102.         SetPixelsQuickly(0,j,row,1+XMAX/3);
  103.     }
  104.     c *=6.0;
  105.     for(j=0;j<YMAX/2;j++){
  106.         k=floor(0.5+79.0*0.5*c*(1.0 + fy[j]));
  107.         k+=91;
  108.         for(i=0;i<1+XMAX/3;i++)row[i]=k;
  109.         SetPixelsQuickly(XMAX/3,j,row,1+XMAX/3);
  110.     }
  111.     c *=6.0;
  112.     for(j=0;j<YMAX/2;j++){
  113.         k=floor(0.5+79.0*0.5*c*(1.0 + fy[j]));
  114.         k+=171;
  115.         for(i=0;i<1+XMAX/3;i++)row[i]=k;
  116.         SetPixelsQuickly(2*XMAX/3,j,row,1+XMAX/3);
  117.     }
  118.  
  119.     /* compute three clut entries that ought to produce equal luminances */
  120.     AA=LToV(&LR,LR.LMax/4.0);
  121.     printf("%f cd/m^2 equivalent number is %f\n",VToL(&LR,AA),AA);
  122.     i=251;
  123.     A=AA;
  124.     a=A/LR.r;
  125.     if(a>255.) n=255;
  126.     else n=a;
  127.     LR.table[i].rgb.red=n<<8;
  128.     A -= n*LR.r;
  129.     a=A/LR.g;
  130.     if(a>255.) n=255;
  131.     else n=a;
  132.     LR.table[i].rgb.green=n<<8;
  133.     A -= n*LR.g;
  134.     a=A/LR.b;
  135.     if(a>255.) n=255;
  136.     else n=a;
  137.     LR.table[i].rgb.blue=n<<8;
  138.     A -= n*LR.b;
  139.     i++;
  140.     A=AA;
  141.     a=A/LR.g;
  142.     if(a>255.) n=255;
  143.     else n=a;
  144.     LR.table[i].rgb.green=n<<8;
  145.     A -= n*LR.g;
  146.     a=A/LR.b;
  147.     if(a>255.) n=255;
  148.     else n=a;
  149.     LR.table[i].rgb.blue=n<<8;
  150.     A -= n*LR.b;
  151.     a=A/LR.r;
  152.     if(a>255.) n=255;
  153.     else n=a;
  154.     LR.table[i].rgb.red=n<<8;
  155.     A -= n*LR.r;
  156.     i++;
  157.     A=AA;
  158.     a=A/LR.b;
  159.     if(a>255.) n=255;
  160.     else n=a;
  161.     LR.table[i].rgb.blue=n<<8;
  162.     A -= n*LR.b;
  163.     a=A/LR.r;
  164.     if(a>255.) n=255;
  165.     else n=a;
  166.     LR.table[i].rgb.red=n<<8;
  167.     A -= n*LR.r;
  168.     a=A/LR.g;
  169.     if(a>255.) n=255;
  170.     else n=a;
  171.     LR.table[i].rgb.green=n<<8;
  172.     A -= n*LR.g;
  173.     i++;
  174.     for(i=251;i<254;i++) printf("%4d,%4d,%4d = %6.2f == %7.3f cd/m^2\n",
  175.         LR.table[i].rgb.red/256,LR.table[i].rgb.green/256,LR.table[i].rgb.blue/256,
  176.         LToV(&LR,GetLuminance(NULL,&LR,i)), GetLuminance(NULL,&LR,i));
  177.     LoadLuminances(device,&LR,251,253);
  178.     
  179.     /* Display stripes */
  180.     for(i=0;i<XMAX;) {
  181.         for(k=0;k<10;k++)row[i++]=251;
  182.         for(k=0;k<10;k++)row[i++]=252;
  183.         for(k=0;k<10;k++)row[i++]=253;
  184.     }
  185.     for(j=YMAX/2;j<YMAX;j++)SetPixelsQuickly(0,j,row,XMAX);
  186.     
  187.     printf("Hit return to quit.");
  188.     getchar();
  189.     SetPort(oldWindow);
  190.     SetGDevice(oldGDHandle);
  191.     GDDisposeWindow(device,window);
  192.     RestoreCluts();
  193.     abort();
  194. }
  195.